/**
 * 
 */
package com.travelsky.app.security.support;

import org.springframework.security.context.SecurityContextHolder;
import org.springframework.security.ui.WebAuthenticationDetails;

import com.travelsky.app.persistence.User;


/**
 * @author zhougc
 * 
 */
public class SecurityUserHolder {

	/**
	 * Returns the current user
	 * 
	 * @return current user  if not exisit return null
	 */
	public static User getCurrentUser() {
	    System.out.println(SecurityContextHolder.getContext().getAuthentication());
		if(SecurityContextHolder.getContext().getAuthentication() == null){
			return null;
		}
		return (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
	}
	public static String getCurrentUserSessionId(){
		if(SecurityContextHolder.getContext().getAuthentication() == null){
			return null;
		}
		return ((WebAuthenticationDetails) SecurityContextHolder.getContext().getAuthentication().getDetails()).getSessionId();
	}
}
